var app = getApp(),
  a = app.requirejs("core");
Page({
  data: {
    show: false,
    loaded: false,
    list: [],
    page: 1,
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData(options);
    this.getinfo();
  },
  getinfo: function () {
    var that = this,
      id = that.data.id;
    a.get('User/card_record', {
      ucard_id: id,
      page: that.data.page,
      nm_type: that.data.nm_type
    }, function (i) {
      if (i.code == 0) {
        var e = { show: true };
        i.info.length > 0 && (e.page = that.data.page + 1, e.list = that.data.list.concat(i.info), i.info.length < 10 && (e.loaded = true));
        i.info.length == 0 && (e.loaded = true);
        e.count = that.data.list.concat(i.info).length;
        that.setData(e)
      } else {
        a.alert(i.msg);
      }
    }, true)


  },
  /**
      * 下拉刷新
      */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getinfo()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getinfo()
  },
})